#ifndef _COLOR_H_
#define _COLOR_H_

typedef	unsigned long COLOR;
#include "../sleipner_config.h"

/// WII expects a 32bit color stored as ARGB, while DX/OGL expects it stored as RGBA.
#ifdef _PLATFORM_WII
inline COLOR	ColorRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
{
	return ((((r)&0xff)<<24)|(((g)&0xff)<<16)|(((b)&0xff)<<8)|((a)&0xff));
}

inline unsigned char ColorGetG(COLOR col) {
	return (unsigned char)((col>>16)&0xFF);
}
inline unsigned char ColorGetB(COLOR col) {
	return (unsigned char)((col>>8)&0xFF);
}
inline unsigned char ColorGetA(COLOR col) {
	return (unsigned char)((col)&0xFF);
}
inline unsigned char ColorGetR(COLOR col) {
	return (unsigned char)((col>>24)&0xFF);
}
inline float ColorGetGf(COLOR col) {
	return float((col>>16)&0xFF)/255.0f;
}
inline float ColorGetBf(COLOR col) {
	return float((col>>8)&0xFF)/255.0f;
}
inline float ColorGetAf(COLOR col) {
	return float((col)&0xFF)/255.0f;
}
inline float ColorGetRf(COLOR col) {
	return float((col>>24)&0xFF)/255.0f;
}

#else 

#ifdef _PLATFORM_SDL
/// SDL expects a 32bit color stored as BGRA, while DX expects it stored as RGBA.

inline COLOR	ColorRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
{
	return ((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff));
}

inline unsigned char ColorGetA(COLOR col) {
	return (unsigned char)((col>>24)&0xFF);
}
inline unsigned char ColorGetB(COLOR col) {
	return (unsigned char)((col>>16)&0xFF);
}
inline unsigned char ColorGetR(COLOR col) {
	return (unsigned char)((col)&0xFF);
}
inline unsigned char ColorGetG(COLOR col) {
	return (unsigned char)((col>>8)&0xFF);
}
inline float ColorGetAf(COLOR col) {
	return float((col>>24)&0xFF)/255.0f;
}
inline float ColorGetBf(COLOR col) {
	return float((col>>16)&0xFF)/255.0f;
}
inline float ColorGetGf(COLOR col) {
	return float((col>>8)&0xFF)/255.0f;
}
inline float ColorGetRf(COLOR col) {
	return float((col)&0xFF)/255.0f;
}


#else

inline COLOR	ColorRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
{
	return ((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff));
}

inline unsigned char ColorGetA(COLOR col) {
	return (unsigned char)((col>>24)&0xFF);
}
inline unsigned char ColorGetR(COLOR col) {
	return (unsigned char)((col>>16)&0xFF);
}
inline unsigned char ColorGetB(COLOR col) {
	return (unsigned char)((col)&0xFF);
}
inline unsigned char ColorGetG(COLOR col) {
	return (unsigned char)((col>>8)&0xFF);
}
inline float ColorGetAf(COLOR col) {
	return float((col>>24)&0xFF)/255.0f;
}
inline float ColorGetRf(COLOR col) {
	return float((col>>16)&0xFF)/255.0f;
}
inline float ColorGetGf(COLOR col) {
	return float((col>>8)&0xFF)/255.0f;
}
inline float ColorGetBf(COLOR col) {
	return float((col)&0xFF)/255.0f;
}

#endif
#endif // _PLATFORM_WII
inline COLOR	ColorfXRGB(float r, float g, float b)
{
	return ColorRGBA((unsigned char)(r*255), (unsigned char)(g*255), (unsigned char)(b*255), 255);
}

inline COLOR	ColorfRGBA(float r, float g, float b, float a)
{
	return ColorRGBA((unsigned char)(r*255), (unsigned char)(g*255), (unsigned char)(b*255), (unsigned char)(a*255));
}

inline COLOR ColorSetR(COLOR c, unsigned char v) {
	return ColorRGBA(v,ColorGetG(c),ColorGetB(c),ColorGetA(c));
}
inline COLOR ColorSetG(COLOR c, unsigned char v) {
	return ColorRGBA(ColorGetR(c),v,ColorGetB(c),ColorGetA(c));
}
inline COLOR ColorSetB(COLOR c, unsigned char v) {
	return ColorRGBA(ColorGetR(c),ColorGetG(c),v,ColorGetA(c));
}
inline COLOR ColorSetA(COLOR c, unsigned char v) {
	return ColorRGBA(ColorGetR(c),ColorGetG(c),ColorGetB(c),v);
}
inline COLOR ColorSetRf(COLOR c, float v) {
	return ColorSetR(c,(unsigned char)(v*255.0f));
}
inline COLOR ColorSetGf(COLOR c, float v) {
	return ColorSetG(c,(unsigned char)(v*255.0f));
}
inline COLOR ColorSetBf(COLOR c, float v) {
	return ColorSetB(c,(unsigned char)(v*255.0f));
}
inline COLOR ColorSetAf(COLOR c, float v) {
	return ColorSetA(c,(unsigned char)(v*255.0f));
}

#endif // _COLOR_H_
